package cn.tedu.sp03.controller;

import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.UserService;
import cn.tedu.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class UserController {
    @Resource
    private UserService service;

    @GetMapping("/{userId}")
    public JsonResult<User> getUser(@PathVariable Integer userId){
        User user=service.getUser(userId);
        return JsonResult.ok().data(user);

    }

    @GetMapping("/{userId}/score")
    public JsonResult<?> addScore(@PathVariable Integer userId,Integer score){
        service.addScore(userId, score);
        return JsonResult.ok().msg("增加积分成功");


    }

    //象浏览器放回一个空数据，不会报错
    @GetMapping("/favicon.ico")
    public void ico(){


    }

}
